﻿#region Imports
using System.Windows.Forms;
using CommonUtilities.Enums;
using CommonUtilities.Extensions;
using CommonUtilities.Messages;
using CommonUtilities.Util;
using DirectoryAnalyzer.Main;
using DirectoryAnalyzer.ResourceFiles;
#endregion

namespace DirectoryAnalyzer.Events
{
    public static class FormClosingEvent
    {
        public static void _FormClosing(object sender, FormClosingEventArgs e, ref bool supressCloseConfirmation, Form currentForm)
        {
            // Views.frmMessageBox frmMessageBox = new Views.frmMessageBox(); // RKD
            if (!supressCloseConfirmation)
            {
                switch (MessageBoxUtil.Show(Program.IsDebug, ResourceDirectoryAnalyzer.Msg_ExitSubApp.FormatTextFromParams(currentForm.Owner.Text),
                        ResourceDirectoryAnalyzer.App_Confirmation, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                {
                    case DialogResult.Cancel:
                        e.Cancel = true;
                        break;

                    case DialogResult.No:
                        supressCloseConfirmation = true;
                        Notifications.PlaySound(eNotificationSound.LogOff, Program.IsMute);
                        currentForm.Close();
                        break;

                    case DialogResult.Yes:
                        currentForm.Hide();
                        supressCloseConfirmation = true;
                        Notifications.PlaySound(eNotificationSound.Exit, Program.IsMute);
                        Application.Exit();
                        break;

                    case DialogResult.Abort:
                    case DialogResult.Ignore:
                    case DialogResult.None:
                    case DialogResult.OK:
                    case DialogResult.Retry:
                    default:
                        break;
                }
            }
        }
    }
}
